package com.woniu.dao;

import com.woniu.entity.Category;
import com.woniu.entity.dto.CategoryDTO;
import com.woniu.entity.vo.CategoryVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.domain.Pageable;
import java.util.List;

/**
 * (Category)表数据库访问层
 *
 * @author makejava
 * @since 2025-06-10 19:03:23
 */
public interface CategoryDao {
    //查询课程分类信息
    @Select("select id,pid,title,description,count from category where is_delete = 0")
    List<CategoryVO> getCategoryAll();
    //添加课程分类信息
    @Insert("insert into category (pid, title, description, create_time, update_time, creater, updater, count)" +
            "values (#{category.pid}, #{category.title}, #{category.description},NOW(), " +
            "#{category.updateTime},#{category.creater}, #{category.updater}, #{category.count})")
    void addCategory(@Param("category") Category category);
    //修改课程分类信息
    @Update("update category set pid = #{category.pid}, title = #{category.title}, " +
            "description = #{category.description}, update_time = NOW(), " +
            "creater = #{category.creater}, updater = #{category.updater}, " +
            "count = #{category.count} where id = #{category.id}")
    void updCategory(@Param("category") Category category);
    @Update("update category set is_delete = 1,update_time = NOW() where id = #{id}")
    void delCategoryByOne(Integer id);

    List<Category> selCategoryByOne(Category category);

    //   根据pid查找信息
    @Select("SELECT * FROM category WHERE pid = #{pid}")
    List<CategoryDTO> findByPid(Integer pid);

    //   先查找pid=0顶级菜单的信息
    @Select("SELECT * FROM category WHERE pid = 0")
    List<CategoryDTO> findRootCategories();


}

